package ee.roosideSoda.frontend.controller.command;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ee.roosideSoda.backend.model.data.view.KoondandmedGameInterfaceJaoks;
import ee.roosideSoda.backend.services.GameInterfaceService;
import ee.roosideSoda.backend.services.implementations.GameInterfaceServiceImpl;
import ee.roosideSoda.frontend.controller.formstringdataconverters.GameInterfaceFormConverter;

public class TaidaGameInterfaceFormConverterCommand implements Command
{
	
	@Override
	public int taidaKask(HttpServletRequest request,
			HttpServletResponse response) 
	{
		GameInterfaceFormConverter gameInterfaceFormConverter = new GameInterfaceFormConverter();
		GameInterfaceService gameInterfaceServiceImpl = new GameInterfaceServiceImpl();
		
		KoondandmedGameInterfaceJaoks koondandmedGameInterfaceJaoks = gameInterfaceServiceImpl.genereeriKoondandmedGameInterfaceJaoks();
		
		if (koondandmedGameInterfaceJaoks == null)
		{
			request.setAttribute("tehnilineRikeAndmeteSaamisel", "Vabandame, ilmnes tehniline rike andmete saamisel!");
			//request.setAttribute("gameInterfaceFormConverter", gameInterfaceFormConverter);
			return 0;
		}
		else
		{
			gameInterfaceFormConverter.fillWithInitialData(koondandmedGameInterfaceJaoks);
			request.setAttribute("gameInterfaceFormConverter", gameInterfaceFormConverter);
			return 1;
		}
	}
}
